package com.jing.tong.asm.controller;

import com.jing.tong.asm.dto.ShiroUser;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * <p> </p>
 *
 * @author sog
 * @version 1.0
 * @since JDK 1.7
 */
@Controller
public class HomeController {

    @GetMapping(value = {"/", "/index"})
    public String index(Model model) {
        final Subject subject = SecurityUtils.getSubject();
        if (subject == null || !subject.isAuthenticated()) {
            return "redirect:/login";
        }
        final ShiroUser shiroUser = (ShiroUser) subject.getPrincipal();
        model.addAttribute("user", shiroUser);
        return "index";
    }
}
